//
//  ViewController.m
//  ILiangCang
//
//  Created by ZX on 16-4-11.
//  Copyright (c) 2016年 CRQ. All rights reserved.
//

#import "ViewController.h"
#import "Masonry.h"
#import "shopViewController.h"
#import "magazineViewController.h"
#import "shareViewController.h"
#import "expertViewController.h"
#import "personalViewController.h"
#import "shareLeftViewController.h"
#import "expertLeftViewController.h"
#import "personalLeftViewController.h"
#import "ICSDrawerController.h"


@interface ViewController ()<UITabBarDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *isOK = [userDefaults objectForKey:@"OK"];
    if (!isOK) {
        [self doAnimation];
    }
    else
    {
        [self goToNext];
        
    }
}
-(void)doAnimation
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setObject:@"123" forKey:@"OK"];
    [userDefaults synchronize];
    
    UIScrollView *myScro = [UIScrollView new];
    myScro.backgroundColor = [UIColor whiteColor];
    myScro.frame = [UIScreen mainScreen].bounds;
    myScro.pagingEnabled = YES;
    myScro.showsHorizontalScrollIndicator = NO;
    myScro.showsVerticalScrollIndicator = NO;
    [self.view addSubview:myScro];
    [myScro mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(self.view.frame.size.height);
        make.left.right.top.equalTo(self.view);
    }];
    UIView * contentView = [[UIView alloc]init];
    [myScro addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(myScro);
        make.size.mas_equalTo(CGSizeMake(5*self.view.frame.size.width, self.view.frame.size.height));
    }];
    
    for (int i = 0; i<5; i++)
    {
        UIImageView * imageView = [[UIImageView alloc]init];
        imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"guide%d.jpg",i+1]];
        [myScro addSubview:imageView];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(myScro.mas_top).with.offset(0);
            make.bottom.equalTo(myScro.mas_bottom).with.offset(0);
            make.left.equalTo(myScro.mas_left).with.offset(i*self.view.frame.size.width);
            make.width.mas_equalTo(self.view.frame.size.width);
        }];
    }
    
    UIButton * btn = [[UIButton alloc]init];
  //  [btn setBackgroundImage:[UIImage imageNamed:@"guide_go"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [myScro addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(myScro.mas_right).with.offset(-(self.view.frame.size.width/2-35));
        make.bottom.equalTo(myScro.mas_bottom).with.offset(-35);
        make.size.mas_equalTo(CGSizeMake(300, 110));
    }];
}

-(void)btnClick:(UIButton *)sender
{
    UIScrollView *myScro = (UIScrollView *)[sender superview];
    [UIView animateWithDuration:0.25 animations:^{
        myScro.center = CGPointMake(160, -240);
    }completion:^(BOOL finished) {
        [myScro removeFromSuperview];
        [self goToNext];
        
        
    }];
}


    
    
//    CGFloat width = CGRectGetWidth([UIScreen mainScreen].bounds);
//    CGFloat height = CGRectGetHeight([UIScreen mainScreen].bounds);
//    for (int i = 0; i < 5; i++) {
//        UIImageView * navView = [[UIImageView alloc]init];
//        navView.frame = CGRectMake(width*i, 0, width, height);
//        NSString * imageStr = [NSString stringWithFormat:@"guide%d.jpg",i+1];
//        navView.image =[UIImage imageNamed:imageStr];
//        [myScro addSubview:navView];
//        
//    }
//    myScro.contentSize = CGSizeMake(width*4, height);
//    
    
//    UIButton *btn = [UIButton new];
//    btn.backgroundColor = [UIColor clearColor];
//    [btn setBackgroundImage:[UIImage imageNamed:@"guide_go"] forState:UIControlStateNormal];
//    [myScro addSubview:btn];
//    //btn.center = CGPointMake(1120, 450);
//    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.equalTo(myScro.mas_right).offset(width/2);
//        make.bottom.equalTo(myScro.mas_bottom).offset(-30);
//        make.size.mas_equalTo(CGSizeMake(70, 20));
//    }];
//    [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
//   }

-(void)goToNext
{
    shopViewController * shopVC = [[shopViewController alloc]init];
    // shopVC.tabBarItem = [[UITabBarItem alloc]init];
    // selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    shopVC.tabBarItem.image = [[UIImage imageNamed:@"tabbar_shop"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    shopVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabbar_shop_h"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UINavigationController * shopNav = [[UINavigationController alloc]initWithRootViewController:shopVC];
    
    shareViewController * shareVC = [[shareViewController alloc]init];

    

    shareLeftViewController * leftVC = [[shareLeftViewController alloc]init];
    ICSDrawerController * shareDrawerVC = [[ICSDrawerController alloc]initWithLeftViewController:leftVC centerViewController:shareVC];
    shareDrawerVC.tabBarItem.image = [[UIImage imageNamed:@"tabbar_perfectware"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    shareDrawerVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabbar_perfectware_h"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
        UINavigationController * shareNav = [[UINavigationController alloc]initWithRootViewController:shareDrawerVC];
    
    
    
    magazineViewController * magazineVC = [[magazineViewController alloc]init];
    magazineVC.tabBarItem.image = [[UIImage imageNamed:@"tabbar_special"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    magazineVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabbar_special_h"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UINavigationController * magazineNav = [[UINavigationController alloc]initWithRootViewController:magazineVC];
    
    expertViewController * expertVC = [[expertViewController alloc]init];
    expertLeftViewController * expertLeftVC = [[expertLeftViewController alloc]init];
    ICSDrawerController * expertDrawer = [[ICSDrawerController alloc]initWithLeftViewController:expertLeftVC centerViewController:expertVC];
    
    expertDrawer.tabBarItem.image = [[UIImage imageNamed:@"tabbar_activity"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    expertDrawer.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabbar_activity_h"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UINavigationController * expertNav = [[UINavigationController alloc]initWithRootViewController:expertDrawer];
    
    personalViewController * perVC = [[personalViewController alloc]init];
    personalLeftViewController * perLeftVC = [[personalLeftViewController alloc]init];
    ICSDrawerController * perDrawer = [[ICSDrawerController alloc]initWithLeftViewController:perLeftVC centerViewController:perVC];
    perDrawer.tabBarItem.image = [[UIImage imageNamed:@"tabbar_person"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    perDrawer.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabbar_person_h"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UINavigationController * perNav = [[UINavigationController alloc]initWithRootViewController:perDrawer];
    
    UITabBarController * tabBarController = [[UITabBarController alloc]init];
    tabBarController.viewControllers = [NSArray arrayWithObjects:shopNav,magazineNav,shareNav,expertNav,perNav, nil];
    tabBarController.delegate = self;
    UIWindow * window = [UIApplication sharedApplication].delegate.window;
    tabBarController.tabBarItem.imageInsets=UIEdgeInsetsMake(6, 0, -6, 0);
    window.rootViewController = tabBarController;
    

        
}


    


@end
